/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package functions.web;

import com.google.gson.Gson;
import db.op.web.LoginOP;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import route.AbsFunction;

/**
 *
 * @author Administrator
 */
public class Login extends AbsFunction {

    private String userEmail;
    private String password;
    private Map<String, Object> map = new HashMap<>();
    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String execute() {
        
        Boolean result = false;
        LoginOP login = new LoginOP(this);
            Map ret=login.op();
            result=(Boolean) ret.get("status");
        if (result) {
            HttpSession session=getRequest().getSession();
            session.putValue("userKey",ret.get("userKey"));
            map.put("status", 0);
            map.put("redir", "appmanager.action");
        } else {
            map.put("status", 1);
            map.put("message", "用户名或者密码有误");
        }
        Gson gson = new Gson();
        login.onDestroy();
        return gson.toJson(map);
    }

}
